<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$uniacid=$_SESSION['uniacid'];
$mid=$_SESSION['uid'];
$return['setting']=$this->setting;
if($_RQ['op']=='main'){
	$orderid=intval($_RQ['id']);
	$verifycode=$_RQ['verifycode'];
	if (empty($verifycode)) {
			exi('请输入核销码!','error','jy_creditshop/verify.index/');
	}
	$order_verify=$this->pdo_get('verify',array('verifycode'=>$verifycode));
	if (empty($order_verify)) 
	{
		exi('核销码错误,无权核销','error','jy_creditshop/verify.index/');   
	}
	if($orderid){
		$order=pdo_get('jy_creditshop_log',array('uniacid'=>$uniacid,'id'=>$orderid));
	}else{
		$order=pdo_get('jy_creditshop_log',array('uniacid'=>$uniacid,'id'=>$order_verify['logid']));
	}
	foreach($return['setting']['verifymids'] as $item){
		if($item['mid']==$mid){
			$saler = $item;
		}
	}
	if (empty($saler)) 
	{
		exi('您不是该店的核销员,无权核销','error','jy_creditshop/verify.index/');   
	}
	if (empty($order)) {
			exi('订单不存在!','error','jy_creditshop/verify.index/');
	}
	if ($order_verify['isverify'] ==2 || ($order_verify['endtime'] && $order_verify['endtime'] < TIMESTAMP)) {	
		exi('该核销码已失效，使用期限已过!','error','jy_creditshop/verify.index/');		
	}
	if ($order_verify['isverify'] ==1) {	
		exi('该核销码已被使用!','error','jy_creditshop/verify.index/');		
	}
	$order_goods=$this->pdo_getall('goods',array('id'=>$order['goodsid']));
	$return['post']=array(
		'logid'=>$order['id'],
		'verifycode'=>$verifycode,
	);
	$return['order']=$order;
	$return['order_goods']=$order_goods;
	set_html('title','核销');
    exi($return);
}

if($_RQ['op']=='post'){
	$post=get_postdata();
	$orderid=intval($post['orderid']);
	$verifycode=trim($post['verifycode']);
	$this->model('order')->order_verify($verifycode,$_SESSION['uid']);
	exi('核销成功！','','jy_creditshop/verify.index/');
	
}